/*     */ package cn.zzuisa.news.repository.dao;

/*     */
/*     */ import cn.zzuisa.news.entity.Comment;
/*     */ import cn.zzuisa.news.entity.User;
/*     */ import cn.zzuisa.news.form.CommentForm;
/*     */ import cn.zzuisa.news.repository.CommentRepository;
/*     */ import cn.zzuisa.news.util.JDBCUtil;
/*     */ import java.sql.Connection;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;

/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */ public class CommentDAO/*     */ implements CommentRepository
/*     */ {

	Connection conn = null;
	Statement statement = null;
	ResultSet resultSet = null;

	/*     */ public List<Comment> list(Integer NewsId) {
		/* 31 */ conn = JDBCUtil.getConnection();
		/* 32 */ Statement statement = null;
		/* 33 */ ResultSet resultSet = null;
		/* 34 */ String sql = "select id,u_id,news_id,content,createtime from `news_comment` where news_id =" + NewsId
				+ " order by id desc";
		/*     */ try {
			/* 36 */ statement = conn.createStatement();
			/* 37 */ resultSet = statement.executeQuery(sql);
			/* 38 */ List<Comment> comments = new ArrayList<Comment>();
			/* 39 */ while (resultSet.next()) {
				/* 40 */ Comment comment = new Comment();
				/* 41 */ comment.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 42 */ comment.setuId(Integer.valueOf(resultSet.getInt("u_id")));
				/* 43 */ comment.setNewsId(Integer.valueOf(resultSet.getInt("news_id")));
				/* 44 */ comment.setContent(resultSet.getString("content"));
				/* 45 */ comment.setCreatetime(resultSet.getTimestamp("createtime"));
				/* 46 */ comments.add(comment);
				/*     */ }
			/* 48 */ return comments;
			/*     */ }
		/* 50 */ catch (SQLException e) {
			/*     */
			/* 52 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 55 */ JDBCUtil.close(conn, statement, resultSet);
				/* 56 */ } catch (Exception e) {
				/*     */
				/* 58 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 61 */ return null;
		/*     */ }

	/*     */
	/*     */
	/*     */ public User findByUId(Integer id) {
		/* 66 */ Connection conn = JDBCUtil.getConnection();
		/* 67 */ statement = null;
		/* 68 */ resultSet = null;
		/* 69 */ String sql = "select id,u_id,news_id,content,createtime from `news_comment` order by id desc";
		/*     */ try {
			/* 71 */ statement = conn.createStatement();
			/* 72 */ resultSet = statement.executeQuery(sql);
			/* 73 */ List<Comment> comments = new ArrayList<Comment>();
			/* 74 */ while (resultSet.next()) {
				/* 75 */ Comment comment = new Comment();
				/* 76 */ comment.setId(Integer.valueOf(resultSet.getInt("id")));
				/* 77 */ comment.setuId(Integer.valueOf(resultSet.getInt("u_id")));
				/* 78 */ comment.setNewsId(Integer.valueOf(resultSet.getInt("news_id")));
				/* 79 */ comment.setContent(resultSet.getString("content"));
				/* 80 */ comment.setCreatetime(resultSet.getTimestamp("createtime"));
				/* 81 */ comments.add(comment);
				/*     */ }
			/*     */
			/* 84 */ } catch (SQLException e) {
			/*     */
			/* 86 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 89 */ JDBCUtil.close(conn, statement, resultSet);
				/* 90 */ } catch (Exception e) {
				/*     */
				/* 92 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 95 */ return null;
		/*     */ }

	/*     */
	/*     */
	/*     */ public CommentForm add(CommentForm commentForm) {
		/* 100 */ Connection conn = JDBCUtil.getConnection();
		/* 101 */ PreparedStatement preparedStatement = null;
		/* 102 */ int flag = 0;
		/* 103 */ String sql = "insert into `news_comment` (u_id,news_id,content) values(?,?,?)";
		/*     */
		/*     */ try {
			/* 106 */ preparedStatement = conn.prepareStatement(sql);
			/* 107 */ preparedStatement.setInt(1, commentForm.getuId().intValue());
			/* 108 */ preparedStatement.setInt(2, commentForm.getNewsId().intValue());
			/* 109 */ preparedStatement.setString(3, commentForm.getContent());
			/* 110 */ flag = preparedStatement.executeUpdate();
			/* 111 */ } catch (SQLException e) {
			/*     */
			/* 113 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 116 */ JDBCUtil.close(conn, preparedStatement);
				/* 117 */ } catch (Exception e) {
				/*     */
				/* 119 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 122 */ return commentForm;
		/*     */ }
	/*     */ }

/*
 * Location:
 * /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/repository/dao/
 * CommentDAO.class Java compiler version: 8 (52.0) JD-Core Version: 1.0.7
 */